package com.dzl.api;

import com.dzl.api.pojo.Order;
import com.dzl.operation.service.OperationLogService;
import com.dzl.order.pojo.WelfareOrder;
import com.dzl.order.service.WelfareOrderExpService;
import com.dzl.order.service.WelfareOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 虚拟商品(蓝色兄弟)充值API  - 控制层
 * @author WangJian
 * @date 2021/7/17 0017
 */
@Slf4j
@RequestMapping("blueBrothers")
@RestController
public class BlueBrothersController {

    @Autowired
    private WelfareOrderExpService welfareOrderExpService;
    @Autowired
    private WelfareOrderService welfareOrderService;
    @Autowired
    private OperationLogService operationLogService;

    /**
     * 虚拟商品（蓝色兄弟）充值回调
     * @param order 入参
     * @return com.dzl.util.JsonResult<com.dzl.api.pojo.Order>
     * @date 2021/7/13 0013 16:41
     * @author wangjian
     */
    @PostMapping("notify")
    public String notify(Order order) {
        log.info("api notify in");
        log.info("api notify order: " + order.toString());
        //查询订单ID
        WelfareOrder welfareOrder = new WelfareOrder();
        welfareOrder.setOrderNo(order.getOutTradeNo());
        Integer id = welfareOrderService.select(welfareOrder).get(0).getId();
        Integer status = order.getStatus().equals("01")?3:4;
        welfareOrderExpService.updateStatus(id,status);
        //添加日志
        operationLogService.saveBlueCharging(id,order.getStatus().equals("01")?"blueBrother:充值成功":"blueBrother:充值失败");
        return "success";
    }
}
